class Router {
  constructor() {
      this.currentUrl = '';
      this.routers = {};
      // this.addEventListener('load', this.refresh, false);
      // this.addEventListener('hashChange', this.refresh, false);
      this.addEventListener();
      this.addOnHashChange()
  };
  // 首次进入页面的hash
  addEventListener() {
    window.addEventListener('DOMContentLoaded',() => {
      console.log('first load hash: ',location.hash)
    })
  }
  // 监听hash变化(首次进入页面不会触发)
  addOnHashChange() {
    window.onhashchange = (event)=>{
      console.log('oldurl', event.oldURL)
      console.log('newurl', event.newURL)
      console.log('hash', location.hash)
    }
  }
  push(path) {
    location.href = `#/${path}`
  }
  // router = (path, callback) => {
  //     this.routers[path] = callback | function() {};
  // }
  // refresh = () => {
  //     this.currentUrl = location.hash.slice[1] | '/';
  //     // slice
  //     // slice方法，slice(start, end)， 会返回一个新函数，而splice会修改原函数
  //     this.routers[this.currentUrl]();
  // }
}

window.$router  =  new Router();
